﻿#region

using System;
using System.Runtime.Serialization;

#endregion

namespace SharpObservation
{
    /// <summary>
    /// Implements a strongly typed weak reference that implements IWeakReference, allowing it to be used in WeakReferenceList
    /// </summary>
    /// <typeparam name="T">The typeToMatch of object targetted by the weak reference</typeparam>
    [Serializable]
    public class WeakReference<T> : WeakReference, IReference<T>
        where T : class
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="WeakReference{T}"/> class.
        /// </summary>
        /// <param name="target">The target.</param>
        public WeakReference(T target) : base(target)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="WeakReference{T}"/> class.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="trackResurection">if set to <c>true</c> [track resurection].</param>
        public WeakReference(T target, bool trackResurection) : base(target, trackResurection)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="WeakReference{T}"/> class.
        /// </summary>
        /// <param name="info">An object that holds all the data needed to serialize or deserialize the current <see cref="T:System.WeakReference"/> object.</param>
        /// <param name="context">(Reserved) Describes the source and destination of the serialized stream specified by <paramref name="info"/>.</param>
        /// <exception cref="T:System.ArgumentNullException">
        /// 	<paramref name="info"/> is null. </exception>
        protected WeakReference(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
        }

        #region IWeakReference<T> Members

        /// <summary>
        ///   Gets or sets the factory target.
        /// </summary>
        public new T Target
        {
            get { return base.Target as T; }
            set { base.Target = value; }
        }

        #endregion
    }

  
}